package eolica


class LoginCommand {
	String login
	String password
	private u
	
	User getUser() {
		if(!u && login)
			u = User.findByLoginAndPassword(login,password)
		return u
	}
	
	static constraints = {
		login blank:false, validator:{ val, cmd ->
		 if(!cmd.user)
		 	return "user.not.found"
		 }
		password blank:false, validator:{ val, cmd ->
		 if(cmd.user && cmd.user.password != val)
		 	return "user.password.invalid"
		 }
	}
}